<script setup>
import { ref, computed } from 'vue'
// 模拟数据
const employeeData = ref([])

// 搜索相关
const searchQuery = ref('')

// 分页相关
const currentPage = ref(1)
const pageSize = ref(10)
// 过滤后的员工列表
const filteredEmployees = computed(() => {
  return employeeData.value.filter((employee) =>
    employee.name.toLowerCase().includes(searchQuery.value.toLowerCase())
  )
})
// 分页后的员工列表
const pagedEmployees = computed(() => {
  const start = (currentPage.value - 1) * pageSize.value
  const end = start + pageSize.value
  return filteredEmployees.value.slice(start, end)
})

// 总条数
const totalItems = computed(() => filteredEmployees.value.length)

// 总页数
const totalPages = computed(() => Math.ceil(totalItems.value / pageSize.value))

// 处理添加员工
const handleAdd = () => {
  console.log('添加员工')
}

// 处理编辑员工
const handleEdit = (employee) => {
  console.log('编辑员工', employee)
}

// 处理删除员工
const handleDelete = (employee) => {
  console.log('删除员工', employee)
}
</script>
<template>
  <div class="employee-page">
    <!-- 主内容区Card -->
    <div class="content-card">
      <div class="card-header">
        <h2>员工列表</h2>
      </div>

      <!-- 搜索和添加区域 -->
      <div class="search-area">
        <div class="search-wrapper">
          <input
            v-model="searchQuery"
            type="text"
            placeholder="请输入员工姓名"
            class="search-input"
          />
          <span class="search-icon">🔍</span>
        </div>
        <button class="add-button" @click="handleAdd">+ 添加员工</button>
      </div>

      <!-- 表格区域 -->
      <div class="table-wrapper">
        <table class="employee-table">
          <thead>
            <tr>
              <th>员工姓名</th>
              <th>账号</th>
              <th>手机号</th>
              <th>账号状态</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            <tr v-if="filteredEmployees.length === 0">
              <td colspan="5" class="empty-data">暂无数据</td>
            </tr>
            <tr v-for="employee in pagedEmployees" :key="employee.id">
              <td>{{ employee.name }}</td>
              <td>{{ employee.username }}</td>
              <td>{{ employee.phone }}</td>
              <td>
                <span
                  :class="[
                    'status',
                    employee.status === 1 ? 'active' : 'inactive'
                  ]"
                >
                  {{ employee.status === 1 ? '正常' : '禁用' }}
                </span>
              </td>
              <td>
                <button class="action-button" @click="handleEdit(employee)">
                  编辑
                </button>
                <button
                  class="action-button delete"
                  @click="handleDelete(employee)"
                >
                  删除
                </button>
              </td>
            </tr>
          </tbody>
        </table>
      </div>

      <!-- 分页区域 -->
      <div class="pagination">
        <span>共 {{ totalItems }} 条</span>
        <select v-model="pageSize" class="page-size-select">
          <option value="10">10条/页</option>
          <option value="20">20条/页</option>
          <option value="50">50条/页</option>
        </select>
        <button
          :disabled="currentPage === 1"
          @click="currentPage--"
          class="page-button"
        >
          &lt;
        </button>
        <span class="page-info">{{ currentPage }}</span>
        <button
          :disabled="currentPage >= totalPages"
          @click="currentPage++"
          class="page-button"
        >
          &gt;
        </button>
        <span>页</span>
      </div>
    </div>
  </div>
</template>

<style scoped>
.employee-page {
  min-height: 100vh;
  background-color: #f0f2f5;
  padding: 24px;
}

.content-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.03);
  padding: 24px;
}

.card-header {
  margin-bottom: 24px;
}

.card-header h2 {
  font-size: 20px;
  font-weight: 500;
  color: #1f2937;
  margin: 0;
}

.search-area {
  display: flex;
  justify-content: space-between;
  margin-bottom: 24px;
  align-items: center;
}

.search-wrapper {
  position: relative;
  width: 320px;
}

.search-input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 14px;
  transition: all 0.3s;
}

.search-input:focus {
  outline: none;
  border-color: #60a5fa;
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.2);
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #9ca3af;
}

.add-button {
  background-color: #ffd04b;
  border: none;
  padding: 8px 20px;
  border-radius: 4px;
  cursor: pointer;
  color: #000;
  font-weight: 500;
  transition: all 0.3s;
}

.add-button:hover {
  background-color: #ffc53d;
}

.table-wrapper {
  margin: 0 -24px;
  overflow-x: auto;
}

.employee-table {
  width: 100%;
  border-collapse: collapse;
}

.employee-table th,
.employee-table td {
  padding: 16px 24px;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
}

.employee-table th {
  background-color: #f9fafb;
  font-weight: 500;
  color: #4b5563;
}

.employee-table tr:hover {
  background-color: #f9fafb;
}

.empty-data {
  text-align: center;
  color: #6b7280;
  padding: 32px !important;
}

.status {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 14px;
}

.status.active {
  background-color: #ecfdf5;
  color: #059669;
}

.status.inactive {
  background-color: #fef2f2;
  color: #dc2626;
}

.action-button {
  margin-right: 12px;
  padding: 4px 12px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.3s;
}

.action-button:not(.delete) {
  background-color: #eff6ff;
  color: #3b82f6;
}

.action-button:not(.delete):hover {
  background-color: #dbeafe;
}

.action-button.delete {
  background-color: #fef2f2;
  color: #dc2626;
}

.action-button.delete:hover {
  background-color: #fee2e2;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
  color: #4b5563;
}

.page-size-select {
  padding: 4px 8px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  color: #4b5563;
}

.page-button {
  padding: 4px 12px;
  border: 1px solid #d1d5db;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  color: #4b5563;
  transition: all 0.3s;
}

.page-button:not(:disabled):hover {
  border-color: #60a5fa;
  color: #60a5fa;
}

.page-button:disabled {
  cursor: not-allowed;
  color: #9ca3af;
  background-color: #f3f4f6;
}

.page-info {
  padding: 4px 12px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  min-width: 32px;
  text-align: center;
}
</style>
